home *** CD-ROM | disk | FTP | other *** search
- /*---------------------------------------------------------------
- Copyright 1995, Steve Israelson
-
- I own this code. You are free to use this code in any software
- you want. You may not sell this source code at all, you can
- sell your product though. If you want to include this code
- in any code collection (CD-Roms etc) this is OK as long as
- I get a complimentary copy.
- Steve.
-
- Holds a list of regular expression and matches them to an input
- string. Automatically handles all flow control constructs,
- like if-then, while etc.
- If it returns kToken_Unknown, then this token must be parsed
- by the caller.
-
- To evaluate if() statements and other conditional statements
- the parser needs to evaluate numerical expressions. To do
- this, it HAS to call your code, since you are the only one
- that can evaluate variables etc. To do this, you pass in
- the function that evaluates numerical expressions and it
- will get called when it needs to be.
- ---------------------------------------------------------------*/
- #pragma once
- #include "StevesParser.h"
- #include "FlowTokens.h"
-
-
- // used for subroutines
- typedef struct {
- long itsLineNum; // the line number where this subroutine starts
- char itsName[64]; // the name of this subroutine, 64 chars max
- } subroutineEntry;
-
- // used for our stack
- typedef struct {
- long token; // the token we represent
- long itsLineNum; // the line we found this token on
- char *theLabel; // the label we are searching for, for gosub calls only
- Boolean isExecuting; // are we executing code?
- Boolean isSearching; // are we searching?
- Boolean conditionState; // for conditional execution
- } stackEntry;
-
-
- // This type of function will get called to evaluate a numerical expression
- // Implement it and pass it into the constructor.
- typedef long (*numericalExpParser)(char *text, long userData);
-
-
- class MyFlowControl
- {
- public:
- MyFlowControl(numericalExpParser theNumEvaluator, long itsData);
- ~MyFlowControl();
- long Parse(char *text, long *theLineNum);
-
- private:
- LList Stack; // stack, for nesting ifs etc
- LList Subroutines; // list of subroutines and their line nums
- MyParser theParser; // For Control statements
- MyParser expressions; // For if statements, etc
- numericalExpParser evalNumber; // pointer to users number evaluater
- long theUserData; // the users data
-
- void BuildFlowControlParser(void);
- void BuildExpressionParser(void);
- subroutineEntry *FindSubroutine(char *text);
- void AddLongParam(LList *theParams, long theNum);
- void PushOntoStack(long token, long theLineNum, char *theLabel,
- Boolean conditionState, Boolean canExecute,
- Boolean isSearching);
- void PopStack(void);
- Boolean EvalExpression(char *theExpression);
- };
-
-